package com.jung.news.dao.impl;

import java.util.List;

import com.jung.common.HibernateEntityManagerImpl;
import com.jung.exception.SkeletonException;
import com.jung.exception.SkeletonSystemException;
import com.jung.news.dao.NewsHibernateDao;
import com.jung.news.model.News;

public class NewsHibernateDaoImpl  extends HibernateEntityManagerImpl<News> implements NewsHibernateDao {
	public boolean addNews(News news){
		try {
			super.save(news);
			return true;
		} catch (SkeletonSystemException e) {
			e.printStackTrace();
		}
		return false;
	}
	public boolean deleteNews(News news) {
		try {
			super.remove(news);
			return true;
		} catch (SkeletonSystemException e) {
			e.printStackTrace();
		}
		return false;
	}
	public News getNewsById(int id) {
		String hql="from News where id="+id;
		Object object = null;
		try {
			List customerList =super.executeHql(hql); 
			if(customerList.size()<1){
				return null;
			}
			object = customerList.get(0);
		} catch (SkeletonException e) {
			e.printStackTrace();
		}
		News news = (News)object;
		return news;
		//return super.findById(Customer.class, id);
	}
	public News getNewsTheNewest() {
		String hql="from News order by publishTime desc";
		Object object = null;
		try {
			List newsList =super.executeHql(hql); 
			if(newsList.size()<1){
				return null;
			}
			object = newsList.get(0);
		} catch (SkeletonException e) {
			e.printStackTrace();
		}
		News news = (News)object;
		return news;
	}
	
}
